package com.redteam.util;

import java.sql.Time;
import java.util.Date;

/**
 * Does operations on a Time object
 * @author Teddy Karam
 */
public class TimeCalculator {

    private Date startDate;
    private Date endDate;
    private Time startTime;
    private Time endTime;

    /**
     * Constructor for TimeCalculator
     * @param startDate
     * @param endDate
     * @param startTime
     * @param endTime
     */
    public TimeCalculator(Date startDate, Date endDate, Time startTime, Time endTime) {
        this.setStartDate(startDate);
        this.setEndDate(endDate);
        this.setStartTime(startTime);
        this.setEndTime(endTime);
    }

    /**
     *
     * @return milliseconds
     */
    public long getTime() {

        Date sDate = new Date(startDate.getYear(), startDate.getMonth(), startDate.getDay(), startTime.getHours(), startTime.getMinutes(), startTime.getSeconds());
        Date eDate = new Date(endDate.getYear(), endDate.getMonth(), endDate.getDay(), endTime.getHours(), endTime.getMinutes(), endTime.getSeconds());
        long milliseconds = eDate.getTime() - sDate.getTime();
        return milliseconds;
    }

    /**
     *
     * @return days
     */
    public int getNumberOfDays() {

        int days = (int) ((((getTime() / 1000) / 60) / 60) / 24);
        return days;
    }

    /**
     *
     * @return hours
     */
    public int getNumberOfHours() {

        int hours = (int) ((((getTime() / 1000) / 60) / 60)) - (24 * getNumberOfDays());
        return hours;
    }

    /**
     *
     * @return minutes
     */
    public int getNumberOfMinutes() {
        int minutes = (int) ((((getTime() / 1000) / 60)) - ((60 * getNumberOfHours()) + (24 * 60 * getNumberOfDays())));
        return minutes;
    }

    /**
     *
     * @return seconds
     */
    public int getNumberOfSeconds() {
        int seconds = (int) ((((getTime() / 1000))) - ((60 * (getNumberOfMinutes() + (60 * getNumberOfHours()) + (24 * 60 * getNumberOfDays())))));
        return seconds;
    }

    /**
     * @return the startDate
     */
    public Date getStartDate() {
        return startDate;
    }

    /**
     * @param startDate the startDate to set
     */
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    /**
     * @return the endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * @return the startTime
     */
    public Time getStartTime() {
        return startTime;
    }

    /**
     * @param startTime the startTime to set
     */
    public void setStartTime(Time startTime) {
        this.startTime = startTime;
    }

    /**
     * @return the endTime
     */
    public Time getEndTime() {
        return endTime;
    }

    /**
     * @param endTime the endTime to set
     */
    public void setEndTime(Time endTime) {
        this.endTime = endTime;
    }

    @Override
    public String toString() {
        return ""+this.getNumberOfDays()+" d "+ this.getNumberOfHours()+" h "+this.getNumberOfMinutes()+" m "+ this.getNumberOfSeconds()+" s ";
    }

}


